//
//  ZZHomeTableViewCell.m
//  ZuZuBao
//
//  Created by Felix on 2024/4/16.
//

#import "ZZHomeTableViewCell.h"

@interface ZZHomeTableViewCell()

@property (nonatomic, strong) UIImageView * imgView;
@property (nonatomic, strong) UILabel * titLabel;
@property (nonatomic, strong) UILabel * depositLabel;
@property (nonatomic, strong) UILabel * priceLabel;
@property (nonatomic, strong) UIButton * rentButton;

@end

@implementation ZZHomeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = kBackColor;
        // 初始化你的UI组件
        UIView * wView = [[UIView alloc] initWithFrame:CGRectMake(kPadding, 0, kScreenWidth - kPadding * 2, 145)];
        wView.backgroundColor = [UIColor whiteColor];
        wView.layer.cornerRadius = 16;
        wView.layer.masksToBounds = YES;
        [self.contentView addSubview:wView];
        
        self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(12, 16, 112, 112)];
        self.imgView.contentMode = UIViewContentModeScaleAspectFit;
        [wView addSubview:self.imgView];
        
        self.titLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.imgView.frame) + 10, self.imgView.frame.origin.y, wView.frame.size.width - 12 - 112 - 10 - 14, 48)];
        self.titLabel.textColor = k333Color;
        self.titLabel.font = [UIFont systemFontOfSize:16];
        self.titLabel.numberOfLines = 2;
        [wView addSubview:self.titLabel];
        
        self.depositLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.imgView.frame) + 10, CGRectGetMaxY(self.titLabel.frame) + 5, wView.frame.size.width - 12 - 112 - 10 - 14, 16)];
        self.depositLabel.textColor = k999Color;
        self.depositLabel.font = [UIFont systemFontOfSize:14];
        [wView addSubview:self.depositLabel];
        
        self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.imgView.frame) + 10, CGRectGetMaxY(self.depositLabel.frame) + 15, 100, 22)];
        self.priceLabel.textColor = kRGBAColor(0xFF0000, 1);
        self.priceLabel.font = [UIFont boldSystemFontOfSize:20];
        [wView addSubview:self.priceLabel];
        
        self.rentButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.rentButton.frame = CGRectMake(wView.frame.size.width - 12 - 88, CGRectGetMaxY(self.imgView.frame) - 36, 88, 36);
        self.rentButton.layer.cornerRadius = 18;
        self.rentButton.layer.masksToBounds = YES;
        self.rentButton.backgroundColor = [UIColor blackColor];
        [self.rentButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.rentButton setTitle:@"租用" forState:UIControlStateNormal];
        self.rentButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        self.rentButton.userInteractionEnabled = NO;
        [wView addSubview:self.rentButton];
        
    }
    return self;
}

-(void)setCellData:(ZZProductModel *)model {
    NSArray * imgs = [model.imgs componentsSeparatedByString:@","];
    if (imgs.count > 0) {
        [self.imgView sd_setImageWithURL:[NSURL URLWithString:imgs[0]]];
    }
    self.titLabel.text = model.goodsTitle;
    self.depositLabel.text = [NSString stringWithFormat:@"押金:￥%d", model.payAmount];
    
    NSString *string = [NSString stringWithFormat:@"￥%.2f/天", model.orderFee];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
    NSRange helloRange = [string rangeOfString:@"￥"];
    [attributedString setAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14.0]} range:helloRange];
    NSRange worldRange = [string rangeOfString:@"/天"];
    [attributedString setAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14.0]} range:worldRange];
    self.priceLabel.attributedText = attributedString;

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
